home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / N-P / NIFTY / myCShell / event.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-26  |  22.4 KB  |  885 lines  |  [TEXT/KAHL]

  1. /*********************************************************
  2.  "event.c"
  3.  
  4.  by John A. Love, III [ Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.00
  7.  *********************************************************/
  8.  
  9.  
  10. #ifndef __BALLOONS__
  11. #include <Balloons.h>
  12. #endif
  13.  
  14. #ifndef __EPPC__
  15. #include <EPPC.h>
  16. #endif
  17.  
  18. #include <CType.h>
  19.  
  20. #include "protos"
  21.  
  22. #include "globals.h"
  23. #include "extern.h"
  24.  
  25. #include "about.h"
  26. #include "ADBLights.h"
  27. #include "floatingWindow.h"
  28.  
  29.  
  30.  
  31. void    DrawContents (WindowPtr window);        // Local Prototype.
  32.  
  33.  
  34.     Boolean                    aDlgEvent;
  35.     long                    Sleep;
  36.     extern DialogPtr        helpPtr;
  37.     extern Rect                List_Rect, Scroller_Rect;
  38.     extern ListHandle        my_List_Handle;
  39.     extern HelpTopic        topics[MAX_TOPICS];
  40.     extern short            Current_Topic, lastHit;
  41.     extern TEHandle            myTEHandle;
  42.     extern ControlHandle    hScrollBar;
  43.     extern ViewMode            Last_Type;
  44.     extern Boolean            newStyle;
  45.     extern short            currentTopLine;
  46.     extern WindowPeek        frontToolWindow,
  47.                             backToolWindow,
  48.                             frontDocWindow;
  49.  
  50.  
  51.     
  52.  
  53. void    MainEventLoop (void)    {
  54.  
  55.         Boolean            ignore;
  56.         WindowPtr        TheWindow;
  57.         short            windowLoc;
  58.  
  59.         
  60.     Sleep = GetCaretTime();
  61.  
  62.     while (!gDone)    {
  63.     
  64.         if (gWNE)    ignore = WaitNextEvent(everyEvent, &gEvent, Sleep, nil);
  65.         else        ignore = GetNextEvent(everyEvent, &gEvent);
  66.         
  67.         /*
  68.         ** We need to call IsDialogEvent here in order that:
  69.         **        1) our modeless Help Window receive null events.
  70.         **        2) the Help Manager process the HelpItem specified
  71.         **           in the Help Window's DITL resource.
  72.         **
  73.         ** NOTE: We call DialogSelect within HandleMouse(...) and test
  74.         **         for (helpPtr != nil) in our other event-related routines
  75.         **         such as HandleKey(...).  As a result, we do NOT call
  76.         **         DialogSelect here before the switch statement.
  77.         */
  78.         aDlgEvent = IsDialogEvent(&gEvent);
  79.      // if (aDlgEvent)        aDlgEvent = DialogSelect(&gEvent, &helpPtr, &itemHit);
  80.  
  81.         switch    (gEvent.what)    {
  82.  
  83.             case nullEvent:
  84.                 DoPeriodic();
  85.                 // An odd-ball here just for auto-key line arrows:
  86.                 if ( isActive(helpPtr) && (Last_Type == text) )
  87.                     HiliteControl(hScrollBar, drawCntl);
  88.                 break;
  89.  
  90.             case mouseDown: 
  91.                 /* Fills in 'TheWindow': */
  92.                 windowLoc = FindWindow(gEvent.where, &TheWindow);
  93.                 HandleMouse(&gEvent, TheWindow, windowLoc);
  94.  
  95.             case mouseUp: break;
  96.  
  97.             case keyDown:
  98.             case autoKey:
  99.                 HandleKey(&gEvent);        // Then, fall thru ...
  100.  
  101.             case keyUp: break;
  102.  
  103.             case updateEvt:
  104.                 HandleUpdate((WindowPtr) gEvent.message);
  105.  
  106.             case diskEvt: break;
  107.  
  108.             case activateEvt:
  109.                 HandleActivate((WindowPtr) gEvent.message);
  110.  
  111.             case networkEvt:
  112.             case driverEvt: break;
  113.  
  114.             case app1Evt:
  115.             case app2Evt:
  116.             case app3Evt: break;
  117.  
  118.             case osEvt:            /* MultiFinder Event = app4Evt */
  119.  
  120.                 switch (gEvent.message >> 24)    {    /* High byte */
  121.  
  122.                     case mouseMovedMessage: break;        // See HandleCursor().
  123.  
  124.                     case suspendResumeMessage: 
  125.  
  126.                         if (gEvent.message & resumeFlag)    {
  127.                             gInForeGround = true;
  128.                             ResetBalloons(gSaveBalloons);
  129.                             gBalloonsUp = gSaveBalloons;
  130.                             TResume();
  131.                         }    /* Resume */
  132.                         
  133.                         else    {
  134.                             gInForeGround = false;
  135.                             
  136.                             /* Remember, deActivate & Activate Events generally
  137.                             ** come in pairs, with deActivate first in line.
  138.                             ** SO ... we hide the silly things and re-show them
  139.                             ** after the Resume partner has finished.            */
  140.                             
  141.                             gSaveBalloons = gBalloonsUp;    // Where we're at !!!
  142.                             ResetBalloons(gStartBalloons);    // On Day Numero Uno !!!
  143.                             TSuspend();
  144.                         };    /* Suspend */
  145.                     
  146.                 }    /* switch (gEvent.message >> 24) */
  147.  
  148.                 break;    /* MultiFinder Event */
  149.  
  150.             case kHighLevelEvent:
  151.  
  152.                 HideBalloons(gBalloonsUp);        /*  ... because of my Alert Dialog. */
  153.                 if (HelpManagerActive())
  154.                     if (HMGetHelpMenuHandle(&gHelpMenu) == noErr)
  155.                         if (gHelpMenu != nil)
  156.                             /* Disable "Show Balloons": */
  157.                             DisableItem(gHelpMenu, kHMShowBalloonsItem);
  158.  
  159.                 DoHighLevelEvent(&gEvent);
  160.  
  161.                 ShowBalloons(gBalloonsUp);
  162.                 if (HelpManagerActive())
  163.                     if (HMGetHelpMenuHandle(&gHelpMenu) == noErr)
  164.                         if (gHelpMenu != nil)
  165.                              /* Reset it: */
  166.                             EnableItem(gHelpMenu, kHMShowBalloonsItem);
  167.  
  168.             default: break;
  169.             
  170.         }    /* switch    (gEvent.what) */
  171.  
  172.     }    /* !gDone */
  173.  
  174. }    /* MainEventLoop */
  175.  
  176.  
  177.  
  178. void    HandleMouse (EventRecord *event, WindowPtr window, short part)    {
  179.  
  180.         short            whatHit, thePart, itemHit, nCols;
  181.         Point            myPt;
  182.         Boolean            DoubleClick;
  183.         Cell            cellHit;            // Cell = a Point.
  184.         ControlHandle    hControl;
  185.         short            oldValue;
  186.         
  187.  
  188.     switch (part)     {
  189.  
  190.         case inContent:
  191.         
  192.             if ( ((WindowPeek)window)->hilited == false )    {
  193.                 TSelectWindow(window);
  194.                 return;
  195.             }
  196.         
  197.             if (window == (WindowPtr)frontDocWindow)    {
  198.                 
  199.                 if (window == helpPtr)
  200.                 {
  201.                 
  202.                 /* Oh Oh ... _IsDialogEvent and _DialogSelect both test
  203.                 ** for our Dialog being the front window.  BUT ... with a
  204.                 ** floating window(s), the latter is the REAL front window.
  205.                 **                 SO ... on with the trickery !!!                */
  206.                 
  207.                         /* I coulda used:
  208.                         **        savedWindowList = WindowList;
  209.                         **
  210.                         ** This did work, though I really don't know why ???
  211.                         ** ... at least it worked UNTIL I incorporated
  212.                         **     Balloon Help and then the Floating Window
  213.                         **       got overwritten:                                 */
  214.  
  215.                         WindowPtr        savedGhostWindow = GhostWindow;
  216.                         Boolean            alreadyRestored = false;
  217.                         
  218.                     if (backToolWindow)        GhostWindow = (WindowPtr) backToolWindow;
  219.                     
  220.                     if ( IsDialogEvent(event) &&
  221.                          DialogSelect(event, &helpPtr, &whatHit) )        {
  222.                         myPt = event->where;
  223.                         GlobalToLocal(&myPt);
  224.  
  225.                         if (whatHit == OK_Button)    {
  226.                             GhostWindow = savedGhostWindow;
  227.                             alreadyRestored = true;
  228.                             Kill_Help_Window();
  229.                         }
  230.  
  231.                         else if ((whatHit == Next_Button) || (whatHit == Prev_Button))
  232.                             H_Scroll_Picture(whatHit);
  233.  
  234.                         else if ( PtInRect(myPt, &List_Rect) )    {
  235.                             DoubleClick = LClick(myPt, event->modifiers, 
  236.                                                  my_List_Handle);
  237.                             cellHit = LLastClick(my_List_Handle);
  238.                             nCols = (**my_List_Handle).dataBounds.right;
  239.                             itemHit = cellHit.v * nCols;
  240.                             if ((itemHit != lastHit) &&
  241.                                 PtInRect(cellHit, &(**my_List_Handle).dataBounds))    {
  242.                                 lastHit = itemHit;
  243.                                 H_Handle_List_Event(itemHit);
  244.                             }
  245.                         }
  246.  
  247.                         else if ( PtInRect(myPt, &Scroller_Rect)
  248.                                   &&
  249.                                   (topics[Current_Topic].screen_mode == text) )        {
  250.                             thePart = FindControl(myPt, helpPtr, &hControl);
  251.                             oldValue = GetCtlValue(hControl);
  252.                             switch (thePart)    {
  253.                         
  254.                                 case inThumb:
  255.                                     if ( TrackControl(hControl, myPt, nil) )    {
  256.                                         H_Scroll_Text(oldValue, 
  257.                                                       GetCtlValue(hControl));
  258.                                         currentTopLine = GetLineNbr(newStyle,
  259.                                                         myTEHandle,
  260.                                                         (**myTEHandle).viewRect.top -
  261.                                                         (**myTEHandle).destRect.top);
  262.                                     }
  263.                                     break;
  264.                                 
  265.                                 case inUpButton:    case inDownButton:
  266.                                 case inPageUp:        case inPageDown:
  267.                                     TrackControl(hControl, myPt,
  268.                                                  (ProcPtr)&H_Scroll_Filter);
  269.                             
  270.                             }    /* end switch (thePart) */
  271.                         }
  272.  
  273.                     }    /* DialogSelect */
  274.  
  275.                     if (!alreadyRestored)    GhostWindow = savedGhostWindow;
  276.                     
  277.                 }    /* in content of HELP Window */
  278.                 
  279.                 else    /* in another window */        {
  280.                 
  281.                 
  282.                 
  283.                 }    /* NOT in HELP Window */
  284.                 
  285.             }    /* in frontDocWindow */
  286.             
  287.             else if (window == (WindowPtr)frontToolWindow)        {
  288.             
  289.                 if (helpPtr == nil)
  290.                     Create_Help();
  291.                 else if (helpPtr != (WindowPtr)frontDocWindow)
  292.                     TSelectWindow(helpPtr);
  293.                     
  294.             }    /* in frontToolWindow */
  295.             
  296.             else if (TGetWKind((WindowPeek)window) == toolKind)
  297.                 /* Clicked in a Tool Window in back somewhere.
  298.                 ** ... remember, ALL floating Tool Windows are
  299.                 ** hilited unless we're suspended or a DA is
  300.                 ** active in the foreground (under System 6).
  301.                 ** Therefore, our starting test for non-hiliting
  302.                 ** would NOT have been triggered.                 */
  303.                 TSelectWindow(window);
  304.             
  305.             /* Clicked in back Document Window -- see start of inContent.
  306.                DAs are handled by case = inSysWindow.
  307.             else        TSelectWindow(window);                            */
  308.                         
  309.             break;    /* inContent */
  310.  
  311.         case inDrag:    
  312.             TDragWindow(window, event);
  313.             break;
  314.  
  315.         case inGoAway:
  316.             if (TrackGoAway(window, event->where))
  317.                 if (window == helpPtr)        Kill_Help_Window();
  318.                 else                        TCloseWindow(window);
  319.             break;
  320.  
  321.         case inGrow:
  322.             {
  323.                 Rect    growRect, updateRect;
  324.                 long    newSize;
  325.                 
  326.             
  327.             // List's Grow Icon there ONLY for appearances:
  328.             if ( isActive(helpPtr) &&
  329.                  PtInRect((**my_List_Handle).mouseLoc, &List_Rect) )        break;
  330.             
  331.             growRect = (**GetGrayRgn()).rgnBBox;    // ... even multiple screens.
  332.             GlobalLocal(&growRect);
  333.             InsetRect(&growRect, scrollWidth, scrollHeight), 
  334.  
  335.             newSize = GrowWindow(window, event->where, &growRect);
  336.             if (newSize == 0)    break;
  337.             
  338.             /* ALL of the following just to avoid that pesky (ARRGH !!!)
  339.             ** double re-draw of the Scroll Bars.  [See _ValidRect within
  340.             ** "Inside Macintosh"]  In addition, note that we start out
  341.             ** by erasing the grow box because upon enlarging the window,
  342.             ** the grow icon remains drawn where it used to be just for a
  343.             ** split second until _BeginUpdate ... _EndUpdate gets around
  344.             ** to erasing it.                                             */
  345.  
  346.             updateRect = window->portRect;
  347.             updateRect.left = updateRect.right + frame - growBoxSize;
  348.             updateRect.top = updateRect.bottom + frame - growBoxSize;
  349.             EraseRect(&updateRect);
  350.  
  351.             InvalidScroll(window);
  352.             SizeWindow(window, LoWord(newSize), HiWord(newSize), true);
  353.             ScrollResize(window);
  354.             ValidScroll(window);
  355.             }
  356.             
  357.             break;        /* inGrow */
  358.  
  359.         case inMenuBar:        /* Process mouse menu command (if any). */
  360.             HandleMenu(event);
  361.             break;
  362.  
  363.         case inSysWindow:    /* Let the system handle the mouseDown. */
  364.             SystemClick(event, window);
  365.             break;
  366.  
  367.         case inZoomIn:
  368.         case inZoomOut:
  369.             DoZoom(window, part);
  370.  
  371.     }    /* end switch (part) */
  372.  
  373. }    /* HandleMouse */
  374.  
  375.  
  376.  
  377. void    HandleKey (EventRecord *event)    {
  378.  
  379.         short            cmd, option, code;
  380.         char            key;
  381.         ControlHandle    okButton, bCtl;
  382.         short            bType;
  383.         Handle            bHandle;
  384.         Rect            bBox;
  385.         Cell            firstCell = {0,0}, currCell, nextCell;
  386.         
  387.         
  388.     cmd = event->modifiers & cmdKey;
  389.     option = event->modifiers & optionKey;
  390.     key = event->message & charCodeMask;
  391.     code = (event->message & keyCodeMask) >> 8;        /* ... into low byte. */
  392.     
  393.     if ( isActive(helpPtr) )        {
  394.     
  395.         if ( (key == '\r') || (key == Enter) || (cmd && (key == '.')) )        {
  396.             okButton = GetDefaultButton(helpPtr);
  397.             SimulateClick(okButton);
  398.             Kill_Help_Window();    
  399.         }    /* <CR>, <Enter> or CMD-period */
  400.         
  401.         else if (cmd)    {        /* NOT CMD-period ... just tested for. */
  402.             /* Covers the case = <CMD-Option>: */
  403.             
  404.             // Keycodes for Mac Plus keyboard, then for all others:
  405.             if ( (code == 0x46) || (code == 0x7B) )        /* Left Arrow */    {
  406.                 GetDItem(helpPtr, Prev_Button, &bType, &bHandle, &bBox);
  407.                 bCtl = (ControlHandle)bHandle;
  408.                 if (
  409.                     (**bCtl).contrlVis    &&        // Hidden when in <Text> mode.
  410.                     ((**bCtl).contrlHilite == ON )
  411.                    )    H_Scroll_Picture(Prev_Button);
  412.                 else    SysBeep(10);
  413.             }
  414.             else if ( (code == 0x42) || (code == 0x7C) )    /* Right Arrow */    {
  415.                 GetDItem(helpPtr, Next_Button, &bType, &bHandle, &bBox);
  416.                 bCtl = (ControlHandle)bHandle;
  417.                 if (
  418.                     (**bCtl).contrlVis    &&
  419.                     ((**bCtl).contrlHilite == ON )
  420.                    )    H_Scroll_Picture(Next_Button);
  421.                 else    SysBeep(10);
  422.             }
  423.             else    HandleMenu(event);
  424.             
  425.         }    /* end ... NOT CMD-period */
  426.         
  427.         else    /* NOT the CMD-key */    {
  428.         
  429.                 short            oldValue, scrollLine, newValue, min, max;
  430.                 long            finalTicks;
  431.                 extern short    maxTopLine;
  432.                 Cell            one;
  433.                 extern Cell        lastCell;
  434.                 short            dRows, dCols, nCols;
  435.                 Boolean            vNext = true, hNext;
  436.  
  437.  
  438.             nCols = (**my_List_Handle).dataBounds.right;
  439.             hNext = nCols > 1;
  440.  
  441.             if ( (code == 0x4D) || (code == 0x7E) )        /* Up Arrow */    {
  442.             
  443.                 if (option)        {    /* Scroll List */
  444.                                     
  445.                     currCell = firstCell;
  446.  
  447.                     if ( !LGetSelect(true,            // next = false means THIS Cell.
  448.                                      &currCell,
  449.                                      my_List_Handle) )    {
  450.                         // nothing to de-select.
  451.                         nextCell = firstCell;
  452.                     }
  453.                     else    {
  454.                     
  455.                         LSetSelect(false, currCell, my_List_Handle);
  456.  
  457.                         if ( EqualPt(currCell, firstCell) )    {
  458.                             nextCell = lastCell;
  459.                         }
  460.                         else    {    // Too bad there's NOT a routine LPrevCell() ?!*!?
  461.                             nextCell = currCell;    /* Start where we left off. */
  462.                             ;
  463.                             if (currCell.h == 0)    /* in first column */    {
  464.                                 dRows = -1;
  465.                                 dCols = nCols - 1;
  466.                             }
  467.                             else    /* over one or more columns */    {
  468.                                 dRows = 0;
  469.                                 dCols = -1;
  470.                             }
  471.                             SetPt(&one, dCols, dRows);
  472.                             ;
  473.                             /* Adding a negative # = subtracting a positive one: */
  474.                             AddPt(one, &nextCell);
  475.                         }    /* end: currCell != firstCell */
  476.                         
  477.                     }    /* end: a Cell is already selected */
  478.                     
  479.                     LSetSelect(true, nextCell, my_List_Handle);
  480.                     
  481.                     if ( !PtInRect(nextCell, &(**my_List_Handle).visible) )
  482.                         LAutoScroll(my_List_Handle);
  483.                         
  484.                     H_Handle_List_Event(nextCell.v * nCols);
  485.                     
  486.                 }    /* end: scrolling list */
  487.                 
  488.                 else if ( (Last_Type == text) &&
  489.                           /* 'tis active */
  490.                           ((*hScrollBar)->contrlMax > 0) )    {    /* Scroll Text */
  491.                           
  492.                     min = GetCtlMin(hScrollBar);
  493.                     max = GetCtlMax(hScrollBar);
  494.                     oldValue = GetCtlValue(hScrollBar);
  495.                     scrollLine = GetLineHeight(newStyle, myTEHandle, currentTopLine);
  496.                     newValue = oldValue - scrollLine;
  497.                     if (newValue <= min)        {
  498.                         newValue = min;
  499.                         currentTopLine = 1;
  500.                     }
  501.                     else    --currentTopLine;
  502.                     ;
  503.                     if (newValue != oldValue)    {    /* Avoid blinking Thumb. */
  504.                         HiliteControl(hScrollBar, inUpButton);
  505.                         ;
  506.                         SetCtlValue(hScrollBar, newValue);
  507.                         Delay(4, &finalTicks);
  508.                         H_Scroll_Text(oldValue, newValue);
  509.                         ;
  510.                         // Keep hilited for autoKey Event:
  511.                         if (event->what == keyDown)
  512.                             HiliteControl(hScrollBar, drawCntl);
  513.                     }
  514.                     else    {
  515.                         HiliteControl(hScrollBar, drawCntl);
  516.                         SysBeep(10);
  517.                     }
  518.  
  519.                 }    /* end: scrolling text */
  520.                 
  521.             }    /* end: Up Arrow */
  522.             
  523.             else if ( (code == 0x48) || (code == 0x7D) )    /* Down Arrow */    {
  524.             
  525.                 if (option)        {    /* Scroll List */
  526.                                 
  527.                     currCell = firstCell;
  528.  
  529.                     if ( !LGetSelect(true,            // next = false means THIS Cell.
  530.                                      &currCell,
  531.                                      my_List_Handle) )    {
  532.                         // nothing to de-select.
  533.                         nextCell = firstCell;
  534.                     }
  535.                     else    {
  536.                         LSetSelect(false, currCell, my_List_Handle);
  537.                         ;
  538.                         nextCell = currCell;    /* Start where we left off. */
  539.                         if ( !LNextCell(hNext,
  540.                                         vNext,
  541.                                         &nextCell,
  542.                                         my_List_Handle) )
  543.                             nextCell = firstCell;
  544.                     }
  545.                     
  546.                     LSetSelect(true, nextCell, my_List_Handle);
  547.                     
  548.                     if ( !PtInRect(nextCell, &(**my_List_Handle).visible) )
  549.                         LAutoScroll(my_List_Handle);
  550.  
  551.                     H_Handle_List_Event(nextCell.v * nCols);
  552.                     
  553.                 }    /* end: scrolling list */
  554.                 
  555.                 else if ( (Last_Type == text) &&
  556.                           ((*hScrollBar)->contrlMax > 0) )    {    /* Scroll Text */
  557.                           
  558.                     min = GetCtlMin(hScrollBar);
  559.                     max = GetCtlMax(hScrollBar);
  560.                     oldValue = GetCtlValue(hScrollBar);
  561.                     scrollLine = GetLineHeight(newStyle, myTEHandle, currentTopLine);
  562.                     newValue = oldValue + scrollLine;
  563.                     if (newValue >= max)        {
  564.                         newValue = max;
  565.                         currentTopLine = maxTopLine;
  566.                     }
  567.                     else    currentTopLine++;
  568.                     ;
  569.                     if (newValue != oldValue)    {    /* Avoid blinking Thumb. */
  570.                         HiliteControl(hScrollBar, inDownButton);
  571.                         ;
  572.                         SetCtlValue(hScrollBar, newValue);
  573.                         Delay(4, &finalTicks);
  574.                         H_Scroll_Text(oldValue, newValue);
  575.                         ;
  576.                         if (event->what == keyDown)        // Keep hilited for autoKey.
  577.                             HiliteControl(hScrollBar, drawCntl);
  578.                     }
  579.                     else    {
  580.                         HiliteControl(hScrollBar, drawCntl);
  581.                         SysBeep(10);
  582.                     }
  583.  
  584.                 }    /* end: scrolling text */
  585.                 
  586.             }    /* end: Down Arrow */
  587.             
  588.             else    /* a regular character */    {
  589.             
  590.                     short            dataLen = 255, nCell, iCell;
  591.                     char            contents[255];        /* WITHOUT length byte. */
  592.                     extern short    pageCells;
  593.                     Boolean            found = false, cellSelected;
  594.                     short            Help   = 0x72,
  595.                                     Home   = 0x73, End        = 0x77,
  596.                                     PageUp = 0x74, PageDown    = 0x79;
  597.                         
  598.             
  599.                 currCell = firstCell;
  600.                 cellSelected = LGetSelect(true, &currCell, my_List_Handle);
  601.  
  602.                 if (code == Help)
  603.                     nextCell = currCell;
  604.  
  605.                 else if (code == Home)
  606.                     nextCell = firstCell;
  607.                     
  608.                 else if (code == End)
  609.                     nextCell = lastCell;
  610.                     
  611.                 else if (code == PageUp)    {
  612.                     SetPt(&nextCell, currCell.h, currCell.v - pageCells);
  613.                     if ((nextCell.h < firstCell.h) || (nextCell.v < firstCell.v))
  614.                         nextCell = firstCell;
  615.                 }
  616.                 
  617.                 else if (code == PageDown)    {
  618.                     SetPt(&nextCell, currCell.h, currCell.v + pageCells);
  619.                     if ((nextCell.h > lastCell.h) || (nextCell.v > lastCell.v))
  620.                         nextCell = lastCell;
  621.                 }
  622.                 
  623.                 else    {
  624.                 
  625.                     nCell = (lastCell.v + 1) * nCols;
  626.                     while    (!found)    {
  627.                     
  628.                         nextCell = currCell;        /* Begin where we left off. */
  629.                         for (iCell = 1; iCell <= nCell; iCell++)    {
  630.                             LGetCell(contents, &dataLen, nextCell, my_List_Handle);
  631.                             /* If the input is NOT a letter, then we
  632.                             ** advance to the NEXT available letter. */
  633.                             if ( cmpAlpha (key, contents[0]) )        {
  634.                                 found = true;    // So we exit the while-loop
  635.                                 break;            //   after we exit the for-loop.
  636.                             }
  637.                             if ( !LNextCell(hNext, vNext, &nextCell, my_List_Handle) )
  638.                                 // Start over:
  639.                                 nextCell = firstCell;
  640.                         }    /* end: for-loop */
  641.                         
  642.                         /* Okay ... we've cycled around the list once.
  643.                         ** Let's do it again with the next available letter.
  644.                         ** Note that we again start where we left off
  645.                         ** EACH time through the while-loop.                */
  646.                         key = nextAlpha(key);
  647.                         
  648.                     }    /* while NOT found */
  649.                     
  650.                 }    /* end: NOT Home, End etc. */
  651.                                     
  652.                 if (cellSelected)    {
  653.                     if (!EqualPt(nextCell, currCell))    {
  654.                         LSetSelect(false, currCell, my_List_Handle);
  655.                         LSetSelect(true, nextCell, my_List_Handle);
  656.                         if ( !PtInRect(nextCell, &(**my_List_Handle).visible) )
  657.                             LAutoScroll(my_List_Handle);
  658.                         H_Handle_List_Event(nextCell.v * nCols);
  659.                     }
  660.                 }
  661.                 else    /* Nothing selected */    {
  662.                     LSetSelect(true, nextCell, my_List_Handle);
  663.                     if ( !PtInRect(nextCell, &(**my_List_Handle).visible) )
  664.                         LAutoScroll(my_List_Handle);
  665.                     H_Handle_List_Event(nextCell.v * nCols);
  666.                 }
  667.  
  668.             }    /* end ... a regular character */
  669.             
  670.         }    /* end ... NOT the CMD-key */
  671.  
  672.     }    /* end ... active Help Window */
  673.     
  674.     // By testing for the Help key before the CMD-key, we cover the
  675.     // instance = CMD-Help.  Also, we do NOT need to test for an
  676.     // Extended keyboard before looking for the Help key because the
  677.     // code = 0x72 is an ADDITION to prior keyboards:
  678.     
  679.     else if (code == 0x72)    {
  680.         if (helpPtr == nil)                                    Create_Help();
  681.         else if (helpPtr != (WindowPtr)frontDocWindow)        TSelectWindow(helpPtr);
  682.     }
  683.     
  684.     else if (cmd)    {
  685.         if (key == '/')        {    /* CMD-? */
  686.             if (helpPtr == nil)                                Create_Help();
  687.             else if (helpPtr != (WindowPtr)frontDocWindow)    TSelectWindow(helpPtr);
  688.         }
  689.         else                HandleMenu(event);
  690.     }
  691.     
  692.     else    {        /* a regular ole' window */
  693.     
  694.     
  695.     }    /* a regular window */
  696.     
  697. }    /* HandleKey */
  698.  
  699.  
  700.  
  701. /* ====================================================
  702. ** HandleUpdate re-draws any controls, text, or PICTs
  703. ** as well as the Grow Icon and Window Menu Bar if any.
  704. ** ==================================================== */
  705.  
  706. void    HandleUpdate (WindowPtr window)    {
  707.  
  708.         GrafPtr        savedPort;            // Must be local parms because windows
  709.                                         //  are updated in front-to-back order.
  710.  
  711.  
  712.     GetPort(&savedPort);                // Save stuff ...
  713.     SetPort(window);
  714.  
  715.     BeginUpdate(window);
  716.     ;
  717.     DrawContents(window);
  718.     ;
  719.     EndUpdate(window);
  720.  
  721.     SetPort(savedPort);                  /* Reset stuff ... */
  722.  
  723. }    /* HandleUpdate */
  724.  
  725.  
  726.  
  727. void    DrawContents (WindowPtr window)    {
  728.  
  729.  
  730.     ClipRect(&window->portRect);
  731.     
  732.     if (window == helpPtr)    H_Handle_Update();
  733.     else    {
  734.         EraseRect(&window->portRect);
  735.         DrawControls(window);
  736.         if ( hasGrowIcon(window) )        DrawGrowIcon(window);
  737.         
  738.         
  739.         
  740.         
  741.     }    /* NOT Help Window */
  742.  
  743. }    /* DrawContents */
  744.  
  745.  
  746.  
  747. void    HandleActivate (WindowPtr window)    {
  748.  
  749.  
  750.     SetPort(window);
  751.  
  752.     if (gEvent.modifiers & activeFlag)    DoActivate(window);
  753.     else                                DoDeactivate(window);
  754.  
  755.     PeriodicMenus();                    /* Crisper appearance if here also. */
  756.  
  757. }    /* HandleActivate */
  758.  
  759.  
  760.  
  761. /* -----------------------------------------------
  762. ** Need to separate them because we're trying to
  763. ** make this blasted thing MultiFinder-compatible:
  764. ** ----------------------------------------------- */
  765.  
  766. void    DoActivate (WindowPtr window)    {
  767.  
  768.         short    theWKind;
  769.  
  770.  
  771.     SetPort(window);
  772.  
  773.     theWKind = TGetWKind((WindowPeek)window);
  774.     
  775.     if (theWKind == userKind)    {
  776.     
  777.         if (window == helpPtr)        {
  778.             if (Last_Type == text)    {
  779.                 if (myTEHandle != nil)    TEActivate(myTEHandle);
  780.                 if (hScrollBar != nil)    HiliteControl(hScrollBar, ON);
  781.             }
  782.             LActivate(true, my_List_Handle);
  783.  
  784.             H_DrawGrowIcon(my_List_Handle);
  785.  
  786.             FrameDefaultButton(helpPtr);
  787.         }
  788.         else    /* NOT Pillera's Help Window */    {
  789.     
  790.     
  791.         }
  792.         
  793.     }    /* end: userKind */
  794.     
  795.     else if (theWKind == toolKind)
  796.         /* This will NEVER be called here because we are either
  797.         ** creating a brand new Tool Window OR we are clicking
  798.         ** in a non-hilited Tool Window (because we have a DA
  799.         ** in the foreground under System 6 we are de-activating)
  800.         ** OR we are clicking in some back Tool Window.  In the
  801.         ** first instance, TShowWindow calls TSelectWindow directly.
  802.         ** In the other instances, HandleMouse also calls
  803.         ** TSelectWindow directly.
  804.         
  805.         TSelectWindow(window);                                        */
  806.         ;
  807.         
  808.     else /* systemKind */    {
  809.     
  810.         /* DAs do their own thing !! */
  811.         
  812.     }
  813.  
  814. }    /* DoActivate */
  815.  
  816.  
  817.  
  818. void    DoDeactivate (WindowPtr window)    {
  819.  
  820.         short    theWKind;
  821.  
  822.  
  823.     theWKind = TGetWKind((WindowPeek)window);
  824.     
  825.     if (theWKind == userKind)    {
  826.     
  827.         if (window == helpPtr)    {
  828.             if (Last_Type == text)    {
  829.                 if (myTEHandle != nil)    TEDeactivate(myTEHandle);
  830.                 if (hScrollBar != nil)    HiliteControl(hScrollBar, OFF);
  831.             }
  832.             LActivate(false, my_List_Handle);
  833.  
  834.             H_DrawGrowIcon(my_List_Handle);
  835.  
  836.             FrameDefaultButton(helpPtr);
  837.         }
  838.         else    {
  839.     
  840.     
  841.         }    /* NOT Pillera's Help Window */
  842.         
  843.     }    /* end: userKind */
  844.     
  845.     else if (theWKind == toolKind)        {
  846.         /* Called ONLY when a DA is activated into the
  847.         ** foreground (under System 6, with the <Option>
  848.         ** key pressed as you open the DA).                */
  849.         
  850.         THiliteTools(false);
  851.         if (frontDocWindow)        {
  852.             HiliteWindow((WindowPtr)frontDocWindow, false);
  853.             DoDeactivate((WindowPtr)frontDocWindow);
  854.         }
  855.         
  856.     }
  857.     
  858.     else /* systemKind */    {
  859.  
  860.         // DAs do their own thing !!
  861.  
  862.     }    /* end: systemKind */
  863.  
  864. }    /* DoDeactivate */
  865.  
  866.  
  867.  
  868. void    DoHighLevelEvent (EventRecord *event)    {
  869. /* Simply calls AEProcessAppleEvent and reports any errors to the client.
  870.    AEProcessAppleEvent looks in its table of registered events and sees if
  871.    the current event is registered.  If so, it calls the routine associated
  872.    with that event.                                                          */
  873.    
  874.         OSErr    err;
  875.          
  876.  
  877.     if (gInitAppleEvents == noErr)    err = AEProcessAppleEvent(event);
  878.     
  879. }    /* DoHighLevelEvent */
  880.  
  881.  
  882.  
  883.  
  884. /*    { end file "event.c" }  */
  885.